package arrayInit;

//convert short array inits like {1,2,3} to "\u0001\u0002\u0003"
public class ShortToUnicodeString extends ArrayInitBaseListener{

    //translate { to "
    @Override
    public void enterInit(ArrayInitParser.InitContext ctx) {
        System.out.print('"');
    }

    //translate } to "
    @Override
    public void exitInit(ArrayInitParser.InitContext ctx) {
        System.out.print('"');
    }

    //translate integer to 4-digit hexadecimal strings
    @Override
    public void enterValue(ArrayInitParser.ValueContext ctx) {
        //内嵌数字时会报错，如 {1, {2,3},4}
        int value = Integer.parseInt(ctx.INT().getText());
        System.out.printf("\\u%04x", value);
    }

}
